/*eslint-disable*/
import "url-search-params-polyfill";//让urlsearchparams兼容IE
import "whatwg-fetch";//让fetch兼容ie8+浏览器
import Vue from 'vue';
import App from './App.vue';
//导入vuex
import Vuex from "vuex";
//导入配置好的路由
import router from "./router";
import Axios from "axios";
import config from "./assets/js/conf/config";
import {request} from "./assets/js/utils/http";
import {INC} from "./store/mutation-types";

//安装Vuex插件
Vue.use(Vuex);

Vue.prototype.$axios=Axios.create({
  baseURL:config.baseApi
});
Vue.prototype.$config=config;
Vue.prototype.$request=request;

//用于配置是否在项目启动时生成提示信息
Vue.config.productionTip = false;

//创建Vuex实例
let store=new Vuex.Store({
  state:{
    count:10,
    users:[
      {id:1,name:"张三",age:18},
      {id:2,name:"李四",age:22},
      {id:3,name:"王五",age:25},
      {id:4,name:"赵六",age:26}
    ]
  },
  getters:{
    /*
       第一个参数：本模块中的state
       第二个参数：其他 getter
       第三个参数：所有模块的state
       */
    getUsers(state,getters,rootState){
      let users=state.users.filter(res=>res.age>18);
      return users;
    }
  },
  mutations:{
    [INC](state,payload){
      // console.log(state,payload);
      state.count+=payload.amount;
    }
  },
  actions:{
    // asyncInc(conText,payload){
    //   // console.log(conText,payload)
    //   setTimeout(()=>{
    //     conText.commit(INC,payload)
    //   },30)
    // }
    asyncInc({commit3},payload){
        // console.log(conText,payload)
        setTimeout(()=>{
          commit(INC,payload)
        },30)
      }
  }
});

new Vue({
  router,//简写 相当于router:router
  //h代表createElement
  store,//注册store
  render: (h) => h(App),
}).$mount('#app');

